﻿/************************* Search box *********************************/
function getNotes(currentTerm, event) {
    if (event.keyCode == 13) {
        DisplaySearchItem();
    }
    if (event.keyCode == 38 || event.keyCode == 40) {
        //alert("Up or Down arrow");
        TraverseList(event.keyCode);
    }
    else {
        if (currentTerm != "") {
            // A proper term has been entered
            var url = requestURL + currentTerm;
            getHTTPRequestObject();
            if (xmlhttp) {
                //alert(url); for debugging
                xmlhttp.open("GET", url, true);
                xmlhttp.onreadystatechange = callback;
                xmlhttp.send(null);
            }
        }
        else {

            // No search term entered - empty the div
            var findDIV = document.getElementById("divResults");
            ClearResults();
            //HideDiv(findDIV);        
        }
    }
}

function getHTTPRequestObject() {
    try {
        // Try legacy object first
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            // Try IE implementation now
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        // We must be using a Mozilla-based browser
        // so create a native request object now
        xmlhttp = new XMLHttpRequest();
    }
}

function callback() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var strResponseText = xmlhttp.responseText;
            //alert(strResponseText);
            //var endIndex = (strResponseText.indexOf("@"));
            //strResponseText = strResponseText.substr(0,endIndex);
            if (strResponseText != strResponseTextCompare) {
                ClearResults();
                strResponseTextCompare = strResponseText;
                eval("var objResults = " + strResponseText);
                var divResults = document.getElementById("divResults");
                var tblTable = document.createElement("table");
                var tablebody = document.createElement("tbody");
                var tablerow, tablecell, tablenode;
                var count = objResults.Results.records.length;
                var j = 0;
                var divWidth = 0;

                tblTable.id = "tblProduct";
                tableLength = 0;
                rIndex = -1;

                // loop through each of the rows in the result
                for (var i = 0; i < count; i++) {
                    var currenttext = objResults.Results.records[i].Notes
                    /*
                    // determine the div width
                    if (i > j)
                    {
                    j = i;
                    divWidth = 0;
                    document.getElementById("divResults").style.width = divWidth;
                    } 
                    {
                    divWidth += currenttext.length;
                    } */

                    // we'll create each table row and append it to the
                    // table body
                    tablerow = document.createElement("tr");
                    tablerow.id = "tr" + i;
                    tablecell = document.createElement("td");
                    tablecell.id = "td" + i;

                    // build the cell attributes and functions
                    tablecell.setAttribute("border", "0");
                    tablecell.setAttribute("align", "left");
                    tablecell.onmouseover = function() { this.className = 'mouseOver'; };
                    tablecell.onmouseout = function() { this.className = 'mouseOut'; };
                    tablecell.onclick = function() { ReplaceInput(this); };
                    tablenode = document.createTextNode(currenttext);
                    tablecell.appendChild(tablenode);
                    tablerow.appendChild(tablecell);
                    tablebody.appendChild(tablerow);
                }

                // add the table body to the table
                tblTable.appendChild(tablebody);
                // add the table to the div tag
                divResults.appendChild(tblTable);
                tableLength = i - 1;
                if (count > 0) {
                    var findDIV = document.getElementById("divResults");
                    ShowDiv(findDIV);
                }
            }
        }
    }
}

function ReplaceInput(tablecell) {
    // swap Input box value with the value selected by
    // the users mouse click
    var inputbox = document.getElementById("txtProductSearch");
    inputbox.value = tablecell.firstChild.nodeValue;
    ClearResults();
    HideDiv("divResults");
}

function TraverseList(keyCode) {
    // swap Input box value with the value selected when
    // the users use up or down arrow key.
    var inputbox = document.getElementById("txtProductSearch");
    var tblTable = document.getElementById("tblProduct");
    var rId = "";

    if (keyCode == 40) {
        if (rIndex < tableLength) {
            if (rIndex > -1) {
                rId = "td" + rIndex;
                document.getElementById(rId).className = "";
            }
            rIndex += 1;
        }
    }

    if (keyCode == 38) {
        if (rIndex > 0) {
            rId = "td" + rIndex;
            document.getElementById(rId).className = "";
            rIndex -= 1;
        }
    }
    rId = "td" + rIndex;
    document.getElementById(rId).className = "mouseOver";
    inputbox.value = document.getElementById(rId).innerText;

}

function ClearResults() {
    // remove existing rows in results table
    var resultsdiv = document.getElementById("divResults");
    var counter = resultsdiv.childNodes.length;
    for (var i = counter - 1; i >= 0; i--) {
        resultsdiv.removeChild(resultsdiv.childNodes[i]);
    }
    HideDiv("divResults");
}

function ShowDiv(divId) {
    if (document.layers) document.layers[divId].visibility = "show";
    else document.getElementById(divId).style.visibility = "visible";
}

function HideDiv(divid) {
    if (document.layers) document.layers[divid].visibility = "hide";
    else document.getElementById(divid).style.visibility = "hidden";
}

/*************************** end of Search Box *********************/

/*************** Expand a division with up or down image ***********/
function SetDivArea(fieldId, direction) {
    element = document.getElementById(fieldId)
    element1 = document.getElementById(fieldId + "Loc")
    if (direction == fieldId + "up") {
        element1.style.display = "none"
        element.src = "images/AdImgDown.gif"
        element.name = fieldId + "down"
    }
    else {
        element1.style.display = "block"
        element.src = "images/AdImgUp.gif"
        element.name = fieldId + "up"
    }
}
/*********************** end of expanding a division ***************/

/**************** Put a larger photo in a new browser **************/
function Enlarge_photo(url) {
    mywin = open(url, "mywin", "width=720,height=480,scrollbars=0,menubar=0,resizable=0,status=0,toolbar=0,location=0")
}

/************************** end enlarge a photo ********************/

/********************* open a map with google map ******************/
function btnMap_Click() {
    var urlPatientAddress = document.getElementById("txtPatientAddress");
    var url = "http://maps.google.com/maps?saddr=" + urlPatientAddress.value + "&daddr=1431 W Harvard, Gilbert, AZ 85233";
    open(url);
}
/************************ end of open a map ************************/

/************************ pop up a division ************************/
function openIndustry_click(divName, divWidth) {
    var mainShade = document.getElementById("oFilterDIV");
    mainShade.style.height = "1000px";
    var industryDiv = document.getElementById(divName);

    // Finding the current cordinate (x,y) of the top-left corner of the screen after user scroll it.
    var scrOfX = 0, scrOfY = 0; // define the current x, y offset of the screen.
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant   
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;

    }
    // end of finding the current cordinate (x,y).

    var top = scrOfY + 20;
    var left = (screen.width - divWidth) / 2;
    top += "px";
    left += "px";
    mainShade.style.visibility = "visible";
    industryDiv.style.left = left;
    industryDiv.style.top = top;
    industryDiv.style.visibility = "visible";
}

function closeIndustry_click(divName) {
    var mainShade = document.getElementById("oFilterDIV");
    var industryDiv = document.getElementById(divName);
    mainShade.style.visibility = "hidden";
    mainShade.style.height = "760px";
    industryDiv.style.visibility = "hidden";
}

function getScrollY() {
    var scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
    }
    return scrOfY;
}

function getScrollX() {
    var scrOfX = 0;
    if (typeof (window.pageXOffset) == 'number') {
        //Netscape compliant
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfX = document.documentElement.scrollLeft;
    }
    return scrOfX;
}
/**************************** end of pop up a division ***********************/

/********************* This part is for user login ***************************/
function openLoginDiv(divId, element) {
    var loginDiv = document.getElementById(divId);

    //close all open divisions
    /*if (document.layers) {
    document.layers["employerLoginDiv"].visibility = "hide";
    document.layers["employeeLoginDiv"].visibility = "hide";
    }    
    else {
    document.getElementById("employerLoginDiv") = "hidden";
    document.getElementById("employeeLoginDiv") = "hidden";
    }*/

    //set left and top position for the division based on the element in HTML DOM
    loginDiv.style.left = ((document.getElementById(element).offsetLeft) + 50) + "px";
    loginDiv.style.top = (document.getElementById(element).offsetTop + 35) + "px";
    /*
    //check login name and password if there are such cookies.
    if (checkCookie("loginName") == false) {        
    setCookie("loginName","",365);
    setCookie("loginPass","",365);
    }

    //initiate login name and password
    if (divId == "employerLoginDiv") {        
    document.getElementById("txtEmployerLoginName").value = getCookie("loginName");        
    document.getElementById("pwdEmployerLoginPassword").value = getCookie("loginPassword");        
    if (document.getElementById("txtEmployerLoginName").value == null || document.getElementById("txtEmployerLoginName").value == "")
    {   document.getElementById("cbxRememberEmployer").checked = false;}
    else 
    {   document.getElementById("cbxRememberEmployer").checked = true; }           
    }
    else {
    document.getElementById("txtJobSeekerLoginName").value = getCookie("loginName");
    document.getElementById("pwdJobSeekerLoginPassword").value = getCookie("loginPassword");
    if (document.getElementById("txtJobSeekerLoginName").value == null || document.getElementById("txtJobSeekerLoginName").value == "")
    document.getElementById("cbxRememberJobSeeker").checked = false;
    else document.getElementById("cbxRememberJobSeeker").checked = true;
    }    
    */
    if (divId == "employerLoginDiv") CheckRememberMe("employer");
    else if (divId == "jobSeekerLoginDiv") CheckRememberMe("jobSeeker");

    //show division
    if (document.layers) document.layers[divId].visibility = "show";
    else loginDiv.style.visibility = "visible";
}

/****************** check remember me for login *********************/
function CheckRememberMe(subject) {
    var txtLoginName = "txt";
    var pwdLoginPass = "pwd";
    var cbxRemember = "cbxRemember";
    if (subject == "admin") {
        txtLoginName += "AdminLoginName";
        pwdLoginPass += "AdminLoginPassword";
        cbxRemember += "Admin";
    }
    if (subject == "employer") {
        txtLoginName += "EmployerLoginName";
        pwdLoginPass += "EmployerLoginPassword";
        cbxRemember += "Employer";
    }
    if (subject == "jobSeeker") {
        txtLoginName += "JobSeekerLoginName";
        pwdLoginPass += "JobSeekerLoginPassword";
        cbxRemember += "JobSeeker";
    }

    //check login name and password if there are such cookies.
    if (checkCookie("loginName") == false) {
        setCookie("loginName", "", 365);
        setCookie("loginPass", "", 365);
    }

    //initiate login name and password
    document.getElementById(txtLoginName).value = getCookie("loginName");
    document.getElementById(pwdLoginPass).value = getCookie("loginPassword");
    if (document.getElementById(txtLoginName).value == null || document.getElementById(txtLoginName).value == "") {
        document.getElementById(cbxRemember).checked = false;
    }
    else {
        document.getElementById(cbxRemember).checked = true;
    }
}
/****************** end of check remember me ***********************/

function closeLoginDiv(divId) {
    var loginDiv = document.getElementById(divId);

    //hide division
    if (document.layers) document.layers[divId].visibility = "hide";
    else loginDiv.style.visibility = "hidden";

}

/*************** function get offset of an element in HTML DOM *********************/
function getOffset(el) {
    var _x = 0;
    var _y = 0;
    while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
        _x += el.offsetLeft - el.scrollLeft;
        _y += el.offsetTop - el.scrollTop;
        el = el.parentNode;
    }
    return { top: _y, left: _x };
}
/***************************** end of get offset function **************************/


function checkLogin(loginName, loginPass, divId, tblName) {
    var strError = "";
    var objLoginName = document.getElementById(loginName);
    var objLoginPass = document.getElementById(loginPass);
    if (objLoginName.value.length == 0) strError = "Login name is empty, please re-enter. ";
    if (objLoginPass.value.length == 0) strError += "Login passwork is empty, please re-enter. ";
    if (strError != "") { alert(strError); return; }

    //Login info passed validation rule. Now hash login info.
    var hashLoginName = MD5(trim(objLoginName.value));        
    //var hashLoginName = (trim(objLoginName.value));
    var hashLoginPass = MD5(trim(objLoginPass.value));
    //var hashLoginPass = (trim(objLoginPass.value));
    //objLoginName.value = hashLoginName;    
    //alert("Login name hash: " + hashLoginName);
    //alert("Login pass hash: " + hashLoginPass);

    checkLoginFile(hashLoginName, hashLoginPass, tblName, divId);
    //closeLoginDiv(divId);
    //window.location = url; open either empployer or employee page
}

function checkLoginFile(loginName, loginPass, tblName, divId) {
    var url = "CheckLogin.aspx" + "?loginName=" + loginName + "&loginPass=" + loginPass + "&tableName=" + tblName;
    //alert(url);
    getHTTPRequestObject();
    if (xmlhttp) {
        xmlhttp.open("GET", url, true);
        xmlhttp.onreadystatechange = callbackLoginResult;
        xmlhttp.send(null);
    }
}

function callbackLoginResult() {
    var url = "";
    var loginNameValue = "";
    var loginPassValue = "";
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var strResponseText = xmlhttp.responseText;
            //alert(strResponseText);
            var endIndex = (strResponseText.indexOf("@"));
            strResponseText = strResponseText.substr(0, endIndex);
            endIndex = (strResponseText.indexOf(","));
            var strResult = strResponseText.substr(0, endIndex);
            strResponseText = strResponseText.substr(endIndex + 1);
            endIndex = (strResponseText.indexOf(","));
            var divId = strResponseText.substr(0, endIndex);
            strResponseText = strResponseText.substr(endIndex + 1);
            endIndex = (strResponseText.indexOf(","));
            var tblName = strResponseText.substr(0, endIndex);
            var userId = strResponseText.substr(endIndex + 1);
            //alert("User id: " + userId);
            if (strResult == "true") {
                //if (tblName == "tblEmployers") checkEmployer(divId,tblName,userId);
                //else if (tblName == "tblAdmin") window.location = "adminManage.aspx";
                //else checkJobSeeker(divId,tblName,userId);
                setCookie("adminName", document.getElementById("txtAdminLoginName").value, 1);
                setCookie("adminPass", document.getElementById("pwdAdminLoginPassword").value, 1);
                checkRememberLogin(divId, tblName, userId);
            }
            else {
                setCookie("adminName", "", 365);
                setCookie("adminPass", "", 365);
                alert("Login information are not correct or your account does not exist!");
            }
        }
    }
}

function checkRememberLogin(divId, tblName, userId) {    
    if (tblName == "tblEmployers") {
        if (document.getElementById("cbxRememberEmployer").checked == true) {
            loginNameValue = document.getElementById("txtEmployerLoginName").value;
            loginPassValue = document.getElementById("pwdEmployerLoginPassword").value;
            setCookie("loginName", loginNameValue, 365);
            setCookie("loginPassword", loginPassValue, 365);
        }
        else {
            setCookie("loginName", "", 365);
            setCookie("loginPassword", "", 365);
        }
    }
    if (tblName == "tblJobSeekers") {
        if (document.getElementById("cbxRememberJobSeeker").checked == true) {
            loginNameValue = document.getElementById("txtJobSeekerLoginName").value;
            loginPassValue = document.getElementById("pwdJobSeekerLoginPassword").value;
            setCookie("loginName", loginNameValue, 365);
            setCookie("loginPassword", loginPassValue, 365);
        }
        else {
            setCookie("loginName", "", 365);
            setCookie("loginPassword", "", 365);
        }
    }
    else {
        if (document.getElementById("cbxRememberAdmin").checked == true) {
            loginNameValue = document.getElementById("txtAdminLoginName").value;
            loginPassValue = document.getElementById("pwdAdminLoginPassword").value;
            setCookie("loginName", loginNameValue, 365);
            setCookie("loginPassword", loginPassValue, 365);
            setCookie("adminName", MD5(loginNameValue), 1);
            setCookie("adminPass", MD5(loginPassValue), 1);
            //alert(getCookie("adminName"));
            //alert(getCookie("adminPass"));
        }
        else {
            setCookie("loginName", "", 365);
            setCookie("loginPassword", "", 365);
        }
    }
    //alert("Complete check in login");
    if (tblName != "tblAdmin") closeLoginDiv(divId);    
    if (tblName == "tblEmployers") url = "Employer.aspx?userId=" + userId;
    if (tblName == "tblJobSeekers") url = "JobSeeker.aspx?userId=" + userId;
    if (tblName == "tblAdmin") url = "AdminManage.aspx?userId=" + userId;

    //url = "Employer.aspx?userId=" + userId;
    window.location = url;
}

/******************************* End of the check login part ****************************/

/******************************* Working with Cookies ***********************************/
function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

function checkCookie(c_name) {
    var c_value = "";
    c_value = getCookie(c_name);
    if (c_value != null && c_value != "") {
        return true;
    }
    else {
        return true;
    }
}

/************************************ End of working on cookies **************************/

/**
*
*  MD5 (Message-Digest Algorithm)
*  http://www.webtoolkit.info/
*  hash a string
*
**/

var MD5 = function(string) {

    function RotateLeft(lValue, iShiftBits) {
        return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
    }

    function AddUnsigned(lX, lY) {
        var lX4, lY4, lX8, lY8, lResult;
        lX8 = (lX & 0x80000000);
        lY8 = (lY & 0x80000000);
        lX4 = (lX & 0x40000000);
        lY4 = (lY & 0x40000000);
        lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
        if (lX4 & lY4) {
            return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
        }
        if (lX4 | lY4) {
            if (lResult & 0x40000000) {
                return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
            } else {
                return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
            }
        } else {
            return (lResult ^ lX8 ^ lY8);
        }
    }

    function F(x, y, z) { return (x & y) | ((~x) & z); }
    function G(x, y, z) { return (x & z) | (y & (~z)); }
    function H(x, y, z) { return (x ^ y ^ z); }
    function I(x, y, z) { return (y ^ (x | (~z))); }

    function FF(a, b, c, d, x, s, ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function GG(a, b, c, d, x, s, ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function HH(a, b, c, d, x, s, ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function II(a, b, c, d, x, s, ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function ConvertToWordArray(string) {
        var lWordCount;
        var lMessageLength = string.length;
        var lNumberOfWords_temp1 = lMessageLength + 8;
        var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
        var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
        var lWordArray = Array(lNumberOfWords - 1);
        var lBytePosition = 0;
        var lByteCount = 0;
        while (lByteCount < lMessageLength) {
            lWordCount = (lByteCount - (lByteCount % 4)) / 4;
            lBytePosition = (lByteCount % 4) * 8;
            lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition));
            lByteCount++;
        }
        lWordCount = (lByteCount - (lByteCount % 4)) / 4;
        lBytePosition = (lByteCount % 4) * 8;
        lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
        lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
        lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
        return lWordArray;
    };

    function WordToHex(lValue) {
        var WordToHexValue = "", WordToHexValue_temp = "", lByte, lCount;
        for (lCount = 0; lCount <= 3; lCount++) {
            lByte = (lValue >>> (lCount * 8)) & 255;
            WordToHexValue_temp = "0" + lByte.toString(16);
            WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length - 2, 2);
        }
        return WordToHexValue;
    };

    function Utf8Encode(string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    };

    var x = Array();
    var k, AA, BB, CC, DD, a, b, c, d;
    var S11 = 7, S12 = 12, S13 = 17, S14 = 22;
    var S21 = 5, S22 = 9, S23 = 14, S24 = 20;
    var S31 = 4, S32 = 11, S33 = 16, S34 = 23;
    var S41 = 6, S42 = 10, S43 = 15, S44 = 21;

    string = Utf8Encode(string);

    x = ConvertToWordArray(string);

    a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;

    for (k = 0; k < x.length; k += 16) {
        AA = a; BB = b; CC = c; DD = d;
        a = FF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
        d = FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
        c = FF(c, d, a, b, x[k + 2], S13, 0x242070DB);
        b = FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
        a = FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
        d = FF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
        c = FF(c, d, a, b, x[k + 6], S13, 0xA8304613);
        b = FF(b, c, d, a, x[k + 7], S14, 0xFD469501);
        a = FF(a, b, c, d, x[k + 8], S11, 0x698098D8);
        d = FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
        c = FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
        b = FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
        a = FF(a, b, c, d, x[k + 12], S11, 0x6B901122);
        d = FF(d, a, b, c, x[k + 13], S12, 0xFD987193);
        c = FF(c, d, a, b, x[k + 14], S13, 0xA679438E);
        b = FF(b, c, d, a, x[k + 15], S14, 0x49B40821);
        a = GG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
        d = GG(d, a, b, c, x[k + 6], S22, 0xC040B340);
        c = GG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
        b = GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
        a = GG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
        d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
        c = GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
        b = GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
        a = GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
        d = GG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
        c = GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
        b = GG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
        a = GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
        d = GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
        c = GG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
        b = GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
        a = HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
        d = HH(d, a, b, c, x[k + 8], S32, 0x8771F681);
        c = HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
        b = HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
        a = HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
        d = HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
        c = HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
        b = HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
        a = HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
        d = HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
        c = HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
        b = HH(b, c, d, a, x[k + 6], S34, 0x4881D05);
        a = HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
        d = HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
        c = HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
        b = HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
        a = II(a, b, c, d, x[k + 0], S41, 0xF4292244);
        d = II(d, a, b, c, x[k + 7], S42, 0x432AFF97);
        c = II(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
        b = II(b, c, d, a, x[k + 5], S44, 0xFC93A039);
        a = II(a, b, c, d, x[k + 12], S41, 0x655B59C3);
        d = II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
        c = II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
        b = II(b, c, d, a, x[k + 1], S44, 0x85845DD1);
        a = II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
        d = II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
        c = II(c, d, a, b, x[k + 6], S43, 0xA3014314);
        b = II(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
        a = II(a, b, c, d, x[k + 4], S41, 0xF7537E82);
        d = II(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
        c = II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
        b = II(b, c, d, a, x[k + 9], S44, 0xEB86D391);
        a = AddUnsigned(a, AA);
        b = AddUnsigned(b, BB);
        c = AddUnsigned(c, CC);
        d = AddUnsigned(d, DD);
    }

    var temp = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d);

    return temp.toLowerCase();
}

/*************************************** End of MD5 hashing ************************************/

/********************************** trim, ltrim, rtrim for string ******************************/
function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}
function ltrim(stringToTrim) {
    return stringToTrim.replace(/^\s+/, "");
}
function rtrim(stringToTrim) {
    return stringToTrim.replace(/\s+$/, "");
}

/**************************** End of trim, ltrim, rtrim for string ******************************/

/*********************************** Update employer ********************************************/

// checkEmail function to determine if email address of new employer is duplicate or not
function checkEmail(strEmail, tblName) {
    if (strEmail == "") {
        alert("Your email address is empty! Please re-enter it.");
        return true;
    }
    var url = "CheckEmail.aspx" + "?cat1=" + strEmail + "&cat2=" + tblName;
    getHTTPRequestObject();
    if (xmlhttp) {
        //alert("getGiftDetails function: " + url); //for debugging
        xmlhttp.open("GET", url, true);
        xmlhttp.onreadystatechange = callbackEmailResult;
        xmlhttp.send(null);
    }
}

function callbackEmailResult() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var strResponseText = xmlhttp.responseText;

            //get the actual response text            
            var endIndex = (strResponseText.indexOf("@"));
            strResponseText = strResponseText.substr(0, endIndex);

            //get result from email checking
            if (strResponseText == "duplicate") {
                alert("Duplicate email, please enter another one.");
                //document.getElementById("clt00_ContentPlaceHolder1_strUserId").value = "duplicate email";
            }
            else {
                if (ValidateEmployerFields("ctl00_ContentPlaceHolder1_")) proceedUpdate("ctl00_ContentPlaceHolder1_");
            }
        }
    }
}

function ValidateEmployerFields(prefix) {
    //alert("validating employer fields...");
    var strResult = "";
    if (document.getElementById(prefix + "txtEmployerName").value == "") {
        strResult = ". Employer name is empty! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtAddress").value == "") {
        strResult += ". Street address is empty! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtCity").value == "") {
        strResult += ". City is empty! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtState").value == "") {
        strResult += ". State is emplty! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtZipCode").value == "") {
        strResult += ". Zip Code is emplty! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtPhone").value == "") {
        strResult += ". Phone number is emplty! Please enter it." + "\n";
    }
    else {
        var strPhone = document.getElementById(prefix + "txtPhone").value;
        //strResult += strPhone;
        //alert("Result = " + strResult);
        var strAreaCode = strPhone.substr(0, 3);
        //alert("Area code = " + strAreaCode);
        var strPhone1 = strPhone.substr(4, 3);
        //alert("phone part 1 = " + strPhone1);
        var strPhone2 = strPhone.substr(8);
        //alert("phone part 2 = " + strPhone2);
        //alert("char at 3 is "+strPhone.substr(3,1)+", char at 7 is "+strPhone.substr(7,1));
        if (isNaN(strAreaCode) || isNaN(strPhone1) || isNaN(strPhone2)) {
            strResult += ". Phone number format is invalid! Please re-enter it.";
        }
        else {
            if ((strPhone.substr(3, 1) != ".") || (strPhone.substr(7, 1) != ".")) {
                strResult += ". Phone number format is invalid! Please re-enter it.";
            }
        }
    }
    if (document.getElementById(prefix + "txtEmail").value == "") {
        strResult += ". Email address is emplty! Please enter it." + "\n";
    }
    else {
        var strEmail = document.getElementById(prefix + "txtEmail").value;
        if (strEmail.search("@") == -1) strResult += ". Email address does not have @! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtSecurityAnswer").value == "") {
        strResult += ". Security answer is emplty! Please enter it." + "\n";
    }

    if (strResult == "") return true;
    else {
        alert(strResult);
        return false;
    }
}

//Update employer profile
function updateEmployer(prefix) {
    if (checkPassword(prefix)) {
        if (document.getElementById(prefix + "txtUserId").value == "") {
            checkEmail(document.getElementById(prefix + "txtEmail").value, "tblEmployers");
        }
        else {
            if (ValidateEmployerFields(prefix)) proceedUpdate(prefix);
        }
    }
}

function proceedUpdate(prefix) {
    var url = "UpdateEmployer.aspx?";
    var ddl = document.getElementById(prefix + "ddlSecurityQuestion");
    var strUserId = document.getElementById(prefix + "txtUserId");
    var selectedIndex = ddl.selectedIndex;
    if (checkPassword(prefix)) {
        url += "userId=" + document.getElementById(prefix + "txtUserId").value;
        //alert("User Id: " + document.getElementById(prefix+"txtUserId").value);
        url += "&employerName=" + document.getElementById(prefix + "txtEmployerName").value;
        url += "&address=" + document.getElementById(prefix + "txtAddress").value;
        url += "&city=" + document.getElementById(prefix + "txtCity").value;
        url += "&state=" + document.getElementById(prefix + "txtState").value;
        url += "&zipCode=" + document.getElementById(prefix + "txtZipCode").value;
        url += "&phone=" + document.getElementById(prefix + "txtPhone").value;
        url += "&email=" + document.getElementById(prefix + "txtEmail").value;
        url += "&timeContact=" + document.getElementById(prefix + "txtTimeContact").value;
        url += "&dayContact=" + document.getElementById(prefix + "txtDayContact").value;
        if (document.getElementById(prefix + "rbnPhone").checked) {
            url += "&preferredMethod=phone";
        }
        else {
            url += "&preferredMethod=email";
        }
        url += "&loginName=" + document.getElementById(prefix + "hashLoginName").value;
        url += "&loginPass=" + document.getElementById(prefix + "hashLoginPass").value;
        url += "&securityQuestion=" + selectedIndex;
        url += "&securityAnswer=" + document.getElementById(prefix + "txtSecurityAnswer").value;

        //alert(url);
        window.location = url;
    }
}

/********************** End of update employer *********************/

/**************************** Check key press **********************/
function checkKeyPress(e) {
    var text = "";
    //text += window.event.keyChar;
    //document.getElementById("ctl00_ContentPlaceHolder1_txtPassword").value = text;
    var evtobj = window.event ? event : e //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
    var unicode = evtobj.charCode ? evtobj.charCode : evtobj.keyCode
    var actualkey = String.fromCharCode(unicode);
    text += actualkey;
    //text += unicode;
    document.getElementById("ctl00_ContentPlaceHolder1_txtPassword").value += text;
    //if (actualkey=="a")
    //document.body.style.fontSize="120%"
    //if (actualkey=="z")
    //document.body.style.fontSize="100%"
    //}
    //document.onkeypress=textsizer    
}

/********************* display edit division **********************/
function displayEditDiv(fieldId) {
    var element = document.getElementById(fieldId + "Div");
    var element1 = document.getElementById("jobDiv");
    var leftPanel = "ctl00_ContentPlaceHolder1_txtLeftPanel";
    //alert(document.getElementById(leftPanel));
    if (document.getElementById(leftPanel).value == "          Job Listing") {
        document.getElementById(leftPanel).width = "196px";
        document.getElementById(leftPanel).value = "Edit Employer Profile";
        element.style.display = "block";
        element1.style.display = "none";
    }
    else {
        document.getElementById(leftPanel).width = "102px";
        document.getElementById(leftPanel).value = "          Job Listing";
        element.style.display = "none";
        element1.style.display = "block";
    }
}

/*********************** end of display division ************************/

/************************* forgot password part *************************/
function openForgotPasswordDiv(divId, tagName, tblName) {
    var strLoginName = document.getElementById("txtEmployerLoginName").value;
    if (strLoginName == "") {
        alert("Email address is empty! Please enter it.");
        return false;
    }
    document.getElementById("txtLoginName").value = strLoginName;
    checkForgotPass(strLoginName, tblName, divId, tagName);
    //        openLoginDiv(divId,tagName);
}

function checkForgotPass(strLoginName, tblName, divId, tagName) {
    strLoginName = MD5(strLoginName);
    var url = "CheckForgotPassword.aspx" + "?cat1=" + strLoginName + "&cat2=" + tblName;
    getHTTPRequestObject();
    if (xmlhttp) {
        //alert("getGiftDetails function: " + url); //for debugging
        xmlhttp.open("GET", url, true);
        xmlhttp.onreadystatechange = callbackForgotPassResult;
        xmlhttp.send(null);
    }
}

function callbackForgotPassResult() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var strResponseText = xmlhttp.responseText;

            //get the actual response text
            //alert(strResponseText);            
            var endIndex = (strResponseText.indexOf("@"));
            strResponseText = strResponseText.substr(0, endIndex);
            //alert(strResponseText);
            if (strResponseText == "") {
                alert("Your email address is invalid! Please re-enter email address");
                return false;
            }
            else {
                endIndex = (strResponseText.indexOf(","));
                document.getElementById("userId").value = strResponseText.substr(0, endIndex);
                strResponseText = strResponseText.substr(endIndex + 1);
                endIndex = (strResponseText.indexOf(","));
                document.getElementById("txtSecurityQuestion").value = strResponseText.substr(0, endIndex);
                //alert(document.getElementById("txtSecurityQuestion").value);
                strResponseText = strResponseText.substr(endIndex + 1);
                document.getElementById("txtCorrectAnswer").value = strResponseText;
                //alert(document.getElementById("txtSecurityAnswer").value);
                openLoginDiv("employerForgotPasswordDiv", "employerLoginLink");
            }
            //alert(strResponseText);
        }
    }
}

function forgotPassSubmit() {
    if (document.getElementById("txtSecurityAnswer").value == document.getElementById("txtCorrectAnswer").value) {
        window.location = "employer.aspx?userId=" + document.getElementById("userId").value;
    }
    else {
        alert("Your security answer does not match! Please re-enter or call 480-633-3392 ext.25 - ext.31!");
    }
}
/**************************** end of forgot password part *************************/

/**************************** Display Job Listing *********************************/

function checkJobSubmitData(prefix) {
    var strErr = "";
    //var strCity = document.getElementById(prefix+"txtCity").value;
    if (document.getElementById(prefix + "txtCity").value == "") {
        strErr = ". Job city is empty! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtPayRate").value == "") {
        strErr += ". Pay rate is empty! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtJobDescription").value == "") {
        strErr += ". Job description is empty! Please copy and paste it." + "\n";
    }
    if (strErr == "") return true;
    else {
        alert(strErr);
        return false;
    }
}

function displayJobListing(divId, prefix, userType) {
    var cat1 = document.getElementById(prefix + "ddlIndustries");
    //var strCat1 = ((cat1.selectedIndex) + 1) + "";
    var strCat1 = (cat1.selectedIndex) + "";
    //var cat2 = document.getElementById(prefix+"ddlSkillsets");
    //var strCat2 = ((cat2.selectedIndex) + 1) + "";
    //alert(strCat1 + "," + strCat2);
    //var url = "FetchJobListing.aspx" + "?cat1=" + strCat1 + "&cat2=" + strCat2;
    var url = "FetchJobListing.aspx" + "?cat1=" + strCat1 + "&cat2=" + userType;
    //alert(url);
    getHTTPRequestObject();
    if (xmlhttp) {
        //alert("getGiftDetails function: " + url); //for debugging
        xmlhttp.open("GET", url, true);
        xmlhttp.onreadystatechange = callbackJobListing;
        xmlhttp.send(null);
    }
}

function callbackJobListing() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var strResponseText = xmlhttp.responseText;
            //alert(strResponseText);            
            var endIndex = (strResponseText.indexOf("@"));
            var strJob = strResponseText.substr(0, endIndex);
            //alert("strJob = " + strJob);
            if (strJob == "not found") {
                //alert("Your job search is not found!");
                return false;
            }
            else {
                var userType = strResponseText.substring(endIndex - 1, endIndex);
                //alert("user type: " + userType);
                strResponseText = strResponseText.substr(0, endIndex - 1);

                if (strResponseText != "") {
                    eval("var objResults = " + strResponseText);
                    var divResults = document.getElementById("jobListingDiv");
                    if (document.getElementById("tblJobListing")) ClearJobListing("jobListingDiv");

                    var tableRow, tableCell, tableNode, rowFont;
                    var tblTable = document.createElement("table");
                    var tableBody = document.createElement("tbody");
                    var rowFont = document.createElement("font");
                    var count = objResults.Results.records.length;
                    //var url = "Job.aspx?jobId=";
                    var j = 0;
                    var divWidth = 0;

                    tblTable.id = "tblJobListing";
                    //tblTable.setAttribute("cellspacing", "30px");
                    tableLength = 0;
                    rIndex = -1;
                    // loop through each of the rows in the result
                    var strJobId = "";
                    var strJobTitle = "";
                    var strPostedDate = "";
                    var strCity = "";
                    var strStatus = "";
                    for (var i = 0; i < count; i++) {
                        strJobId = objResults.Results.records[i].JobId;
                        strJobTitle = objResults.Results.records[i].JobTitle;
                        strPostedDate = objResults.Results.records[i].PostedDate;
                        strCity = objResults.Results.records[i].City;
                        strStatus = objResults.Results.records[i].Status;

                        // we'll create each table row and append it to the
                        // table body
                        tableRow = document.createElement("tr");
                        tableRow.id = "tr" + i;

                        // build new table cell
                        tableCell = document.createElement("td");
                        // build the cell attributes and functions
                        tableCell.setAttribute("border", "0px");
                        tableCell.setAttribute("height", "30px");
                        tableCell.onmouseover = function() { this.className = 'mouseOver'; };
                        tableCell.onmouseout = function() { this.className = 'mouseOut'; };
                        tableCell.onclick = function() { linkJob(this, userType); };
                        tableNode = document.createTextNode("Job Id: " + strJobId + "  >>  " + strJobTitle + " - " + strCity + " - " + strStatus);
                        tableCell.appendChild(tableNode);
                        tableRow.appendChild(tableCell);
                        tableBody.appendChild(tableRow);

                        tableRow = document.createElement("tr");
                        tableRow.id = "tr" + i;
                        // build new table cell
                        tableCell = document.createElement("td");
                        tableCell.id = "td1" + i;
                        // build the cell attributes
                        tableCell.setAttribute("border", "0px");
                        tableCell.setAttribute("height", "20px");
                        tableCell.setAttribute("align", "right");
                        tableNode = document.createTextNode("Posted Date:");
                        tableCell.appendChild(tableNode);
                        tableRow.appendChild(tableCell);

                        // build new table cell
                        tableCell = document.createElement("td");
                        // build the cell attributes
                        tableCell.setAttribute("border", "0px");
                        tableCell.setAttribute("height", "10px");
                        tableNode = document.createTextNode(strPostedDate);
                        tableCell.appendChild(tableNode);
                        tableRow.appendChild(tableCell);
                        /*
                        tableCell = document.createElement("td");
                        tableCell.setAttribute("border", "0px");
                        tableCell.setAttribute("height", "20px");
                        tableCell.setAttribute("width", "15%");		                
                        tableNode = document.createTextNode("City:  " + strCity);	    	            
                        tableCell.appendChild(tableNode);
                        tableRow.appendChild(tableCell);
                        */
                        tableBody.appendChild(tableRow);

                    }

                    // add the table body to the table
                    tblTable.appendChild(tableBody);
                    // add the table to the div tag
                    divResults.appendChild(tblTable);
                    tableLength = i - 1;

                    if (count > 0) ShowDiv("jobListingDiv");
                }
            }
        }
    }
}

function linkJob(tablecell, userType) {
    var strJobId = tablecell.firstChild.nodeValue;
    var startIndex = (strJobId.indexOf(":")) + 2;
    var endIndex = (strJobId.indexOf(">"));
    //alert("endIndex = " + endIndex);
    strJobId = trim(strJobId.substring(startIndex, endIndex));
    //alert("user type = " + userType);
    if (userType == "1") window.location = "Job.aspx?jobId=" + strJobId;
    else window.location = "JobDesc.aspx?jobId=" + strJobId;
}

function ClearJobListing(divId) {
    // remove existing rows in results table
    var resultsdiv = document.getElementById(divId);
    var counter = resultsdiv.childNodes.length;
    for (var i = counter - 1; i >= 0; i--) {
        resultsdiv.removeChild(resultsdiv.childNodes[i]);
    }
    HideDiv(divId);
}
/********************** end of job listing part ********************/

/********************** Update job seeker part *********************/

// checkEmail function to determine if email address of new employer is duplicate or not
function checkEmailJobSeeker(strEmail, tblName) {
    if (strEmail == "") {
        alert("Your email address is empty! Please re-enter it.");
        return true;
    }
    var url = "CheckEmail.aspx" + "?cat1=" + strEmail + "&cat2=" + tblName;
    getHTTPRequestObject();
    if (xmlhttp) {
        //alert("getGiftDetails function: " + url); //for debugging
        xmlhttp.open("GET", url, true);
        xmlhttp.onreadystatechange = callbackEmailJobSeekerResult;
        xmlhttp.send(null);
    }
}

function callbackEmailJobSeekerResult() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var strResponseText = xmlhttp.responseText;

            //get the actual response text            
            var endIndex = (strResponseText.indexOf("@"));
            strResponseText = strResponseText.substr(0, endIndex);

            //get result from email checking
            if (strResponseText == "duplicate") {
                alert("Duplicate email, please enter another one.");
                //document.getElementById("clt00_ContentPlaceHolder1_strUserId").value = "duplicate email";
            }
            else {
                if (ValidateJobSeekerFields("ctl00_ContentPlaceHolder1_")) proceedUpdateJobSeeker("ctl00_ContentPlaceHolder1_");
            }
        }
    }
}

function ValidateJobSeekerFields(prefix) {
    var strResult = "";
    if (document.getElementById(prefix + "txtUserName").value == "") {
        strResult = ". User name is empty! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtAddress").value == "") {
        strResult += ". Street address is empty! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtCity").value == "") {
        strResult += ". City is empty! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtState").value == "") {
        strResult += ". State is emplty! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtZip").value == "") {
        strResult += ". Zip Code is emplty! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtPhone").value == "") {
        strResult += ". Phone number is emplty! Please enter it." + "\n";
    }
    else {
        var strPhone = document.getElementById(prefix + "txtPhone").value;
        var strAreaCode = strPhone.substr(0, 3);
        var strPhone1 = strPhone.substr(4, 3);
        var strPhone2 = strPhone.substr(8);
        if (isNaN(strAreaCode) || isNaN(strPhone1) || isNaN(strPhone2)) {
            strResult += ". Phone number format is invalid! Please re-enter it.";
        }
        else {
            if ((strPhone.substr(3, 1) != ".") || (strPhone.substr(7, 1) != ".")) {
                strResult += ". Phone number format is invalid! Please re-enter it.";
            }
        }
    }
    if (document.getElementById(prefix + "txtCell").value == "") {
        strResult += ". Cell phone number is emplty! Please enter it." + "\n";
    }
    else {
        var strCell = document.getElementById(prefix + "txtCell").value;
        var strAreaCode = strCell.substr(0, 3);
        var strCell1 = strCell.substr(4, 3);
        var strCell2 = strCell.substr(8);
        if (isNaN(strAreaCode) || isNaN(strCell1) || isNaN(strCell2)) {
            strResult += ". Cell phone number format is invalid! Please re-enter it.";
        }
        else {
            if ((strCell.substr(3, 1) != ".") || (strCell.substr(7, 1) != ".")) {
                strResult += ". Cell phone number format is invalid! Please re-enter it.";
            }
        }
    }

    if (document.getElementById(prefix + "txtEmail").value == "") {
        strResult += ". Email address is emplty! Please enter it." + "\n";
    }
    else {
        var strEmail = document.getElementById(prefix + "txtEmail").value;
        if (strEmail.search("@") == -1) strResult += ". Email address does not have @! Please enter it." + "\n";
    }
    if ((document.getElementById(prefix + "txtResume").value == "") && (document.getElementById(prefix + "filResume").value == "")) {
        strResult += ". Need to upload or paste your resume! Please enter it." + "\n";
    }
    if (document.getElementById(prefix + "txtSecurityAnswer").value == "") {
        strResult += ". Security answer is emplty! Please enter it." + "\n";
    }

    if (strResult == "") return true;
    else {
        alert(strResult);
        return false;
    }
}

function checkPassword(Prefix) {
    if (((document.getElementById("txtPassword").value) != "") || ((document.getElementById("txtConfirmPassword").value) != "")) {
        if ((document.getElementById("txtPassword").value) == (document.getElementById("txtConfirmPassword").value)) {
            //alert("password valid!");
            document.getElementById(Prefix + "hashLoginName").value = MD5(document.getElementById(Prefix + "txtEmail").value);
            document.getElementById(Prefix + "hashLoginPass").value = MD5(document.getElementById("txtPassword").value);
            return true;
        }
        else {
            alert("Password and confirm password are not the same!");
            return false;
        }
    }
    else {
        if (document.getElementById(Prefix + "txtUserId").value == "") {
            alert("Password is empty! Please enter password.");
            return false;
        }
        else {
            document.getElementById(Prefix + "hashLoginName").value = document.getElementById(Prefix + "txtDataLoginName").value;
            document.getElementById(Prefix + "hashLoginPass").value = document.getElementById(Prefix + "txtDataLoginPass").value;
            return true;
        }
    }
}

//Update employer profile
function updateJobSeeker(prefix) {
    //var result = ValidateJobSeekerFields(prefix);
    //result = checkPassword(prefix);
    if (checkPassword(prefix)) {
        //alert("pass check pass");
        if (document.getElementById(prefix + "txtUserId").value == "") {
            checkEmailJobSeeker(document.getElementById(prefix + "txtEmail").value, "tblJobSeekers");
        }
        else {
            if (ValidateJobSeekerFields(prefix)) proceedUpdateJobSeeker(prefix);
        }
    }
}

function proceedUpdateJobSeeker(prefix) {
    //alert("Begin updating job seeker profile...");
    var url = "UpdateJobSeeker.aspx?";
    var ddl = document.getElementById(prefix + "ddlSecurityQuestion");
    var strUserId = document.getElementById(prefix + "txtUserId");
    var selectedIndex = ddl.selectedIndex;
    if (checkPassword(prefix)) {
        url += "userId=" + document.getElementById(prefix + "txtUserId").value;
        //alert("User Id: " + document.getElementById(prefix+"txtUserId").value);
        url += "&userName=" + document.getElementById(prefix + "txtUserName").value;
        url += "&address=" + document.getElementById(prefix + "txtAddress").value;
        url += "&city=" + document.getElementById(prefix + "txtCity").value;
        url += "&state=" + document.getElementById(prefix + "txtState").value;
        url += "&zip=" + document.getElementById(prefix + "txtZip").value;
        url += "&phone=" + document.getElementById(prefix + "txtPhone").value;
        url += "&cell=" + document.getElementById(prefix + "txtCell").value;
        url += "&email=" + document.getElementById(prefix + "txtEmail").value;
        if (document.getElementById(prefix + "chkRelocate").checked) url += "&relocate=agree";
        else url += "&relocate=notAgree";
        if (document.getElementById(prefix + "chkExpense").checked) url += "&expense=want";
        else url += "&expense=donotWant";
        url += "&twitter=" + document.getElementById(prefix + "txtTwitter").value;
        url += "&linkedIn=" + document.getElementById(prefix + "txtLinkedIn").value;
        url += "&facebook=" + document.getElementById(prefix + "txtFacebook").value;
        url += "&loginName=" + document.getElementById(prefix + "hashLoginName").value;
        url += "&loginPass=" + document.getElementById(prefix + "hashLoginPass").value;
        url += "&securityQuestion=" + selectedIndex;
        url += "&securityAnswer=" + document.getElementById(prefix + "txtSecurityAnswer").value;
        url += "&filResume=" + document.getElementById(prefix + "filResume").value;
        url += "&txtResume=" + document.getElementById(prefix + "txtResume").value;
        //alert(url);
        window.location = url;
    }
}

/********************** end update job seeker  *********************/

/******** Assign LinkedIn and Facebook link to an image button *****/

function LinkedInClick(prefix) {
    var url = document.getElementById(prefix + "txtLinkedIn").value;
    if (url != "") window.location = url;
}

function FacebookClick(prefix) {
    var url = document.getElementById(prefix + "txtFacebook").value;
    if (url != "") window.location = url;
}


/*********************** end of assignment **************************/

/*********************** Clear Admin Cookies ************************/
function ClearAdminCookies() {
    setCookie("adminName", "", 365);
    setCookie("adminPass", "", 365);
    //alert(getCookie("adminName"));
    //alert(getCookie("adminPass"));
    window.location = "Default.aspx";
}
/********************* end of Clear Admin Cookies *******************/

/*********************** Check If Admin Loging In *******************/
function CheckAdminCookies(type) {
    if (getCookie("adminName") == null || getCookie("adminName") == "") {
        //ShowDiv("oFilterDIV");
        alert("You are not authorized to access this page!");
        window.location = "Default.aspx";
        return false;
    }
    CheckBtnGo(type);
}

function CheckBtnGo(type) {
    //try
    //{
    //var btnGo = document.getElementById("btnGo");
    if (document.getElementById("btnGo")) {
        if (type == "2") displayJobListing('jobListingDiv', 'ctl00_ContentPlaceHolder1_', '2');
        else displayJobListing('jobListingDiv', 'ctl00_ContentPlaceHolder1_', '1');
    }
    //}
    //catch(err)
    //{
    //Handle errors here
    //}    
}
/********************* end of Check Admin Loging ********************/

/********************* Change Admin Password ************************/
function changeAdminInfo(loginName, currentPass, newLoginName, newPass, confirmPass) {
    if (document.getElementById(newLoginName).value == null || document.getElementById(newLoginName).value == "") {
        document.getElementById(newLoginName).value = document.getElementById(loginName).value;
    }
    var cat1 = MD5(document.getElementById(loginName).value);
    var cat2 = MD5(document.getElementById(currentPass).value);    
    var cat3 = MD5(document.getElementById(newPass).value);
    var cat4 = MD5(document.getElementById(confirmPass).value);
    var cat5 = MD5(document.getElementById(newLoginName).value);
    
    var url = "ChangeAdminInfo.aspx?cat1=" + cat1 + "&cat2=" + cat2 + "&cat3=" + cat3 + "&cat4=" + cat4 + "&cat5=" + cat5;
    if (cat3 != cat4) {
        alert("Your new password and confirm password are not the same! Please re-enter them.");
        return false;
    }
    //alert(url);
    getHTTPRequestObject();
    if (xmlhttp) {
        xmlhttp.open("GET", url, true);
        xmlhttp.onreadystatechange = callbackChangeAdminPass;
        xmlhttp.send(null);
    }
}

function callbackChangeAdminPass() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var strResponseText = xmlhttp.responseText;
            //alert(strResponseText);
            //get the actual response text            
            var endIndex = (strResponseText.indexOf("@"));
            strResponseText = strResponseText.substr(0, endIndex);
            alert(strResponseText);            
            //get result from changing password
            if (strResponseText == "done") {
                alert("Your password has been successfully changed.");
                setCookie("adminName", MD5(document.getElementById("txtAdminNewLoginName").value), 1);
                setCookie("adminPass", MD5(document.getElementById("pwdAdminNewPassword").value), 1);
                //closeLoginDiv("changePassDiv");
            }
            else {
                alert("Your current login info is not correct! Please re-enter them.");
            }
        }
    }
}

function loadIFrame(iFrame, action) {
    var ifrJobs = document.getElementById(iFrame);
    if (action == "Edit") ifrJobs.src = "EditJobs.aspx";
    if (action == "Add") ifrJobs.src = "AddJobs.aspx";
    if (action == "Delete") ifrJobs.src = "DeleteJobs.aspx";
    if (action == "DeleteList") ifrJobs.src = "DeleteJobListing.aspx";
    if (action == "ChangeLogin") ifrJobs.src = "ChangeLogin.aspx";
}
/********************* end change Admin Password ********************/